package com.bxait.toymail.member.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;


import com.bxait.com.utils.PageUtils;
import com.bxait.com.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

import com.bxait.toymail.member.entity.MemberReceiveAddressEntity;
import com.bxait.toymail.member.service.MemberReceiveAddressService;

import javax.annotation.Resource;


/**
 * import org.apache.shiro.authz.annotation.RequiresPermissions;
 * 会员收货地址
 *
 * @author chen
 * @email 2277411582@qq.com
 * @date 2023-03-13 22:35:49
 */
@RestController
@RequestMapping("member/memberreceiveaddress")
public class MemberReceiveAddressController {

    @Resource
    @Qualifier("memberReceiveAddressService")
    private MemberReceiveAddressService memberReceiveAddressService;

    /*
     * @param memberId
     * @==============History===============<br/>
     * @Description //   根据用户id获取用户地址信息
     * @Date 2023/5/13 2023/5/13
     * @Author < a href="2277411582@qq.com">chen</ a>
     * @return java.util.List<com.bxait.toymail.member.entity.MemberReceiveAddressEntity>
     */
    @GetMapping("/{memeberId}/addresses")
    public List<MemberReceiveAddressEntity> getAddress(@PathVariable("memeberId") Long memberId){
        return memberReceiveAddressService.getAddress(memberId);
    }


    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = memberReceiveAddressService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		MemberReceiveAddressEntity memberReceiveAddress = memberReceiveAddressService.getById(id);

        return R.ok().put("memberReceiveAddress", memberReceiveAddress);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody MemberReceiveAddressEntity memberReceiveAddress){
		memberReceiveAddressService.save(memberReceiveAddress);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody MemberReceiveAddressEntity memberReceiveAddress){
		memberReceiveAddressService.updateById(memberReceiveAddress);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		memberReceiveAddressService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
